//
//  TKHomeViewController.swift
//  TKWBOne
//
//  Created by tiankun on 16/8/23.
//  Copyright © 2016年 1. All rights reserved.
//

import UIKit


private let cellID = "cellID"
class TKHomeViewController: TKBaseViewController {

    private lazy var statusViewModel = TKStatusViewModel()
    override func loadData() {
        print("开始加载数据")
        statusViewModel.loadStatus(pullup: self.isPullup) { (isSuccess, shouldRefresh) in
            self.refreshControl?.endRefreshing()
            self.isPullup = false
            if shouldRefresh {
                self.tableView?.reloadData()
            }
        }
    }
    @objc private func showFriends() {
        let vc = TKTestViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
}

extension TKHomeViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusViewModel.statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        cell.textLabel?.text = statusViewModel.statusList[indexPath.row].text
        return cell
    }

}

extension TKHomeViewController {
    override func setupTableView() {
        super.setupTableView()
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
    }
    

}
